/*#include<math.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;

int y,m,d,day_cnt,f1;

int judge(int year)
{
    if( (year%4==0)&&(year%100!=0) || year%400==0 )return 1;
    else return 0;
}

int main()
{
    int t;cin>>t;
    while(t--)
    {
        day_cnt=f1=0;

        scanf("%d-%d-%d",&y,&m,&d);
        if(judge(y)&&m==2&&d==29)
        {
            cout<<-1<<endl;
            continue;
        }
        if(judge(y)&&m>=3){f1=-1;}
        if(judge(y+18)&&m<3){f1=0;}
        if(judge(y+18)&&m>=3){f1=1;}
        for(int i=0;i<18;i++)
        {
            int yy=y+i;
            if(judge(yy))day_cnt+=366;
            else day_cnt+=365;
        }
        cout<<day_cnt+f1<<endl;
    }
    return 0;

}
*/
/*
13
2004-1-22
2004-2-28
2004-2-29
2004-4-20
2003-2-20
2003-2-28
2003-3-20
2002-2-20
2002-2-28
2002-3-20
2001-2-20
2001-2-28
2001-3-20
*/


#include <iostream>
using namespace std;

int isRun(int n)
{
	return (n % 4 == 0 && n % 100 != 0) || (n % 400 == 0);
}

int fun(int year, int month, int day)
{
	if (month == 2 && day == 29)
		return -1;
	int sum = 0;
	if (isRun(year) && month >= 3)	
		sum = -1;
	
	if (isRun(year + 18) && month < 3)	
		sum = 0;
	
	if (isRun(year + 18) && month >= 3)	
		sum = 1;
		
	for (int i = 0; i < 18; i++)
	{
		if (isRun(year + i))
			sum += 366;
		else
			sum += 365;
	}
	return sum;
}

int main()
{
	int t;
	int year, month, day;
	cin >> t;
	while (t--)
	{
		cin >> year;
		cin.get();
		cin >> month;
		cin.get();
		cin >> day;
		cout << fun(year, month, day) << endl;
	}
	return 0;
}
